//
//  HWAccountDetailsViewController.m
//  HWanGame
//
//  Created by 陈道斌 on 2019/9/12.
//  Copyright © 2019 Chendaobin. All rights reserved.
//

#import "HWAccountDetailsViewController.h"
#import "HWFenXiangGameView.h" //  分享
#import "HWZhanghaoCellCell.h" //   yoxu
#import "HWClinchDealCell.h"
#import "HWBuyAccountController.h" // 购买账号
#import "HWTradingModel.h"
#import "HWLoginController.h"

#import "UIBarButtonItem+Item.h"


@interface HWAccountDetailsViewController ()<UITableViewDelegate,UITableViewDataSource,HWFenXiangGameViewDelegate,UIScrollViewDelegate>
@property(strong,nonatomic) UITableView *mainaTableVie;
@property(strong,nonatomic) UIView    *lowerPartView;
@property(strong,nonatomic) UIView *hederView;
@property(strong,nonatomic) UIView *gameIsIntroducedView;
@property(strong,nonatomic) UIImageView *icoImagView;
@property(strong,nonatomic) UILabel *nameLabel;
@property(strong,nonatomic) UILabel *miashulabel;
@property(strong,nonatomic) UIView *basisView;
@property(strong,nonatomic) NSMutableArray *basisMuArr;
@property(strong,nonatomic) UILabel *priceLabel; //基础信息价格
// 黄色Uiview
@property(strong,nonatomic) UIView *huanbeijiView; //背景Uiview
@property(strong,nonatomic) UILabel *jieshoulabel; //  介绍

@property(strong,nonatomic) UILabel *chushoulabel;  //已出售
//@property(strong,nonatomic) UIImageView *shenheImageView;

// 卖家信息View
@property(strong,nonatomic) UIView *maijiaView; //
@property(strong,nonatomic) UIImageView *shenheImageView;
@property(strong,nonatomic) UILabel *shimingLabel;
@property(strong,nonatomic) UILabel *phonelabel; //
@property(strong,nonatomic) UILabel *zhucelabel;
@property(strong,nonatomic) UILabel *shulian1; // 数量1
@property(strong,nonatomic) UILabel *shulian2;


// 底部按钮
@property(strong,nonatomic)UIButton *lijiButton; //  立即购买按钮
@property(strong,nonatomic)UIButton *shoucangBut; // 收藏
@property(strong,nonatomic)UIButton *fenxiangBut; // 分享


@property(strong,nonatomic)NSDictionary *dataDic;
@property(strong,nonatomic) NSArray *icoimageArr;
@property(strong,nonatomic) NSMutableArray *otherArray;

@property(strong,nonatomic) UIScrollView *scrollView; //


@end

@implementation HWAccountDetailsViewController


-(UITableView *)mainaTableVie {
    
    if (_mainaTableVie == nil
        ) {
        
        _mainaTableVie = [[UITableView alloc]initWithFrame:CGRectMake(0, CF_NavHeight, kScreenW, kScreenH-CF_NavHeight-44-CF_TabbarSafeBottomMargin) style:UITableViewStyleGrouped];
        _mainaTableVie.delegate = self;
        _mainaTableVie.dataSource = self;
        _mainaTableVie.separatorStyle = UITableViewCellSeparatorStyleNone;
        _mainaTableVie.backgroundColor = [UIColor whiteColor];
        
        
        
    }
    return   _mainaTableVie ;
}


-(void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    [self fasongwangluoqingqiu];
    
    [self.navigationController setNavigationBarHidden:NO animated:animated];
    

}




- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    [self setup];
    // 添加底部
    [self addLowerPartView];
    
    // 添加tabview的HederView
    [self addtablviewHeadView];
    
    // l立即购买
  //  [self lijigoumiai];
    
    
  //  [self fasongwangluoqingqiu];
    
}






//发送网络请求
- (void)fasongwangluoqingqiu {
    
    
    
   
    
        NSDictionary *parametes = @{
                                  
                                     @"ios" : @"1",
                                     @"ct" :  @"app",
                                     @"ac" : @"trade_info",
                                     @"id" : self.idStr,
                                     @"uid" : [HWLocallyStoredData getLoginUserID]
                                    };
         
    
    

         [HWWebUtils doGetWithParameters:parametes progress:nil success:^(id response) {

         


             NSString *codeStr =  [NSString stringWithFormat:@"%@",response[@"code"]];

             if ([codeStr intValue] == 1) {

                 self.dataDic = response[@"data"];
                 self.nameLabel.text = self.dataDic[@"gname"];
                 NSURL *url = [NSURL URLWithString:self.dataDic[@"icon"]];
                 
                 [self.icoImagView sd_setImageWithURL:url placeholderImage:nil];
                 self.miashulabel.text =  [NSString  stringWithFormat:@"%@",self.dataDic[@"name"]];
               //   [self.basisMuArr addObject:namelabel];
                 //  NSArray *arr = @[@"上架时间：2019-07-30",@"操作系统：IOS",@"账号名称：九天白浅珆",@"账号区服：上古258服"];
                   NSString *creationTimeStr = [NSString stringWithFormat:@"%@",self.dataDic[@"create_time"]];
                  NSString * creat =  [WMUtil createTime:creationTimeStr setDateFormatString: @"yyyy-MM-dd"];
                  creat = creationTimeStr;
                 
                  creat = [NSString stringWithFormat:@"%@%@",@"上架时间：",creat];
                   NSString *caozuoxito = [NSString stringWithFormat:@"%@",self.dataDic[@"system"]];
                 if ([caozuoxito intValue] == 1) {
                     caozuoxito = [NSString stringWithFormat:@"操作系统：%@",@"安卓"];
                 } else {
                      caozuoxito = [NSString stringWithFormat:@"操作系统：%@",@"ios"];
                 }
                 
                 
                 NSString *zhanghai = [NSString stringWithFormat:@"账号名称：%@",self.dataDic[@"name"]];
                 NSString *sname = [NSString stringWithFormat:@"账号区服：%@",self.dataDic[@"sname"]];
                 NSArray *arr = @[creat,caozuoxito,zhanghai,sname];
                 
                
                 for (int i = 0; i < self.basisMuArr.count ; i++) {
                     UILabel *nameLabel = self.basisMuArr[i];
                     nameLabel.text = arr[i];
                 }
                 
                 // @"￥2000.00";
            //     self.priceLabelpriceLabel.text =  [NSString stringWithFormat:@"%@",self.dataDic[@"money"]];
                 self.priceLabel.text  = [NSString stringWithFormat:@"￥%@",self.dataDic[@"money"]];
           //     self.jiagelabel.text = @"此账号已创建61天累计充值5260元。"; regday
                 self.jieshoulabel.text = [NSString stringWithFormat:@"此账号已创建%@天累计充值%@元。",self.dataDic[@"regday"],self.dataDic[@"pay_money"]];
               //  [self.mainaTableVie reloadData];
                 
                 // status
                 self.phonelabel.text  = [NSString stringWithFormat:@"%@",self.dataDic[@"sellerinfo"][@"phone"]];
                 self.zhucelabel.text = [NSString stringWithFormat:@"已注册 %@",self.dataDic[@"sellerinfo"][@"regday"]];
                 self.shimingLabel.text = [NSString stringWithFormat:@"%@",self.dataDic[@"sellerinfo"][@"shiming"]];
                 
                 self.shulian1.text = [NSString stringWithFormat:@"%@",self.dataDic[@"sellerinfo"][@"selling"]];
                 self.shulian2.text = [NSString stringWithFormat:@"%@",self.dataDic[@"sellerinfo"][@"soldout"]];
                 
                 self.icoimageArr = self.dataDic[@"images"];
                 
              //   self.otherArray = self.dataDic[@"other"];
                 
                 self.otherArray  =  [HWTradingModel mj_objectArrayWithKeyValuesArray:self.dataDic[@"other"]];
                 
                 NSString *shifou = [NSString stringWithFormat:@"%@",self.dataDic[@"shoucang"]];
                 
                 if ([shifou isEqualToString:@"1"]) {
                     self.shoucangBut.selected = YES;
                     
                 } else if ([shifou isEqualToString:@"0"]){
                     
                     self.shoucangBut.selected = NO;
                 }
                 
                 NSString *shop_ok = [NSString stringWithFormat:@"%@", self.dataDic[@"shop_ok"]];
                 
                 if ( [shop_ok intValue] == 0 ) {
                     
                     self.chushoulabel.hidden = YES;
                            self.shenheImageView.hidden = NO;
                            self.lijiButton.backgroundColor = RGB(38, 154, 255);
                    [self.lijiButton setTitle:@"立即购买" forState:UIControlStateNormal];
                    [self.lijiButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
                     
                      self.lijiButton.backgroundColor = [UIColor bm_colorGradientChangeWithSizeView: self.lijiButton];
                            
                    
                     
                 } else {
                     
                     
                
                      self.chushoulabel.hidden = NO;
                      self.shenheImageView.hidden = YES;
                      self.lijiButton.backgroundColor = RGB(216, 216, 216);
                      [self.lijiButton setTitle:@"角色已出售" forState:UIControlStateNormal];
                     self.lijiButton.enabled =  NO;
                      [self.lijiButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
//                             self.lijiButton.backgroundColor = [UIColor bm_colorGradientChangeWithSizeView: self.lijiButton];
//
                     
                 }
                 
                 
               
                 
                 
             } else {
                 
                 
                 
                 
             }
             
             
             
            [self.mainaTableVie reloadData];


         } failure:^(NSString *error) {
             [self.mainaTableVie.mj_header endRefreshing];
             [self.mainaTableVie.mj_footer endRefreshing];
         }];
    
    
    
    
}




- (void)lijigoumiai {
    
    
    NSString *str = @"1";
    if ([str isEqualToString:@"1"]) {
        
        self.chushoulabel.hidden = YES;
        self.shenheImageView.hidden = NO;
       //  self.lijiButton.backgroundColor = RGB(38, 154, 255);
        [self.lijiButton setTitle:@"立即购买" forState:UIControlStateNormal];
        [self.lijiButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        
         self.lijiButton.backgroundColor = [UIColor bm_colorGradientChangeWithSizeView: self.lijiButton];
        
        
    } else {
        
        self.chushoulabel.hidden = NO;
        self.shenheImageView.hidden = YES;
      //  self.lijiButton.backgroundColor = RGB(216, 216, 216);
        [self.lijiButton setTitle:@"角色已出售" forState:UIControlStateNormal];
        [self.lijiButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        
       // self.lijiButton.backgroundColor = [UIColor bm_colorGradientChangeWithSizeView: self.lijiButton];
        
    }
    
    
    
}

- (void)setup {
    
    self.view.backgroundColor = [UIColor whiteColor];
    self.navigationItem.title = @"账号详情";
    self.navigationItem.leftBarButtonItem = [UIBarButtonItem  backItemWithimage:[UIImage imageNamed:@"fanhui"] highImage:[UIImage imageNamed:@"fanhui"] target:self action:@selector(back) title:@"   "];
    [self.view addSubview:self.mainaTableVie];
    
    
}

- (void)back
{
    [self.navigationController popViewControllerAnimated:YES];
}






// 添加低部UIview
- (void)addLowerPartView {
    
    self.lowerPartView = [[UIView alloc]initWithFrame:CGRectMake(0, kScreenH-44-CF_TabbarSafeBottomMargin, kScreenW, 44+CF_TabbarSafeBottomMargin)];
    // self.lowerPartView.backgroundColor = [UIColor yellowColor];
    self.lowerPartView.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:self.lowerPartView];
    
    UIButton *butt  = [UIButton setButtonWithFrame:CGRectMake(65, 7, kScreenW-65*2, 30) Title:@"立即购买" Image:nil Font:13 Color:RGB(255, 255, 155) Target:self Selector:@selector(buttonTap:)];
    butt.backgroundColor = RGB(38, 154, 255);
    butt.layer.cornerRadius = 15;
    butt.layer.masksToBounds = YES;
    self.lijiButton = butt;
    [self.lowerPartView addSubview:butt];
    
    UIButton *butt1  = [UIButton setButtonWithFrame:CGRectMake(7, 0, 50, 44) Title:@"收藏" Image:@"details_sellect_a" Font:10 Color:RGB(178, 178, 178) Target:self Selector:@selector(shoucangTap:)];
    [butt1 setImage:[UIImage imageNamed:@"details_sellect_b"] forState:UIControlStateSelected];
    self.shoucangBut = butt1;
    // butt1.backgroundColor = RGB(38, 154, 255);
    [butt1 layoutButtonWithEdgeInsetsStyle:MKButtonEdgeInsetsStyleTop imageTitleSpace:5];
    [self.lowerPartView addSubview:butt1];
    
    UIButton *butt2  = [UIButton setButtonWithFrame:CGRectMake(kScreenW-65+7, 0, 50, 44) Title:@"分享" Image:@"details_share_a" Font:10 Color:RGB(178, 178, 178) Target:self Selector:@selector(fenxiangTap:)];
    butt2.hidden = YES;
    self.fenxiangBut = butt2;
    
    // butt1.backgroundColor = RGB(38, 154, 255);
    [butt2 layoutButtonWithEdgeInsetsStyle:MKButtonEdgeInsetsStyleTop imageTitleSpace:5];
    [self.lowerPartView addSubview:butt2];
    
    
}

#pragma mark -----  点击立即立即购买按钮
- (void)buttonTap:(UIButton *)sender {
    
    DLog(@"即立即购买");
    
    
//    if ([[HWLocallyStoredData getLoginUserID] isEqualToString:@""]) {
//
//            HWLoginController *login = [[HWLoginController alloc]init];
//            [self.navigationController pushViewController:login animated:YES];
//
//           return;
//     }
    
    
    
    HWBuyAccountController *buy = [[HWBuyAccountController alloc]init];
    if (self.icoimageArr.count > 0) {
        buy.urlstring = self.dataDic[@"images"][0];
    }
    buy.name1str = self.dataDic[@"name"];
    buy.name2str = self.dataDic[@"introduction"];
    buy.name3str = [NSString stringWithFormat:@"累计充值%@", self.dataDic[@"pay_money"]];
    buy.jiageStr = [NSString stringWithFormat:@"%@",self.dataDic[@"money"]];
    buy.idStr = [NSString stringWithFormat:@"%@",self.dataDic[@"id"]];
    
    [self.navigationController pushViewController:buy animated:YES];
    
}

// 点击收藏按钮
- (void)shoucangTap:(UIButton *)sender {
    
    if ([[HWLocallyStoredData getLoginUserID] isEqualToString:@""]) {

        HWLoginController *login = [[HWLoginController alloc]init];
        [self.navigationController pushViewController:login animated:YES];

            return;
    }
    
  //  [self   quxiaoshoucang];
    
    
    if (sender.selected) {
      //  sender.selected = NO;
        [self quxiaoshoucang];
    } else {
       // sender.selected = YES;
        [self shoucanganniucaozuo];

    }
    DLog(@"lmjopojp");
    
}

// 分享
- (void)fenxiangTap:(UIButton *)sender {
    
    DLog(@"分享");
    DLog(@"%@",NSStringFromCGRect(self.view.frame));
    HWFenXiangGameView *FenXiang = [[HWFenXiangGameView alloc]initWithFrame:CGRectMake(0, 0, kScreenW, kScreenH)];
    FenXiang.delegate = self;
    [kKeyWindow addSubview:FenXiang];
    
}




- (void)addtablviewHeadView {
    
    self.hederView  = [[UIView  alloc]initWithFrame:CGRectMake(0, 0, kScreenW, 71+150+86)];
    self.hederView.backgroundColor = [UIColor redColor];
    self.mainaTableVie.tableHeaderView = self.hederView;
    
    self.gameIsIntroducedView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, kScreenW, 71)];
    self.gameIsIntroducedView.backgroundColor = [UIColor whiteColor];
    [self.hederView addSubview: self.gameIsIntroducedView];
    
    
    UIImageView *imageView = [[UIImageView alloc]initWithFrame:CGRectMake(12, 13, 45, 45)];
    imageView.image = [UIImage imageNamed:@"youxiangxiangqing"];
    imageView.layer.cornerRadius = 6;
    imageView.layer.masksToBounds = YES;
    self.icoImagView = imageView;
    [self.gameIsIntroducedView addSubview:imageView];
    
    self.nameLabel = [[UILabel alloc]initWithFrame:CGRectMake(imageView.right+8, 17, 100, 14)];
    self.nameLabel.text = @"苍穹仙迹";
    NSMutableAttributedString *string = [[NSMutableAttributedString alloc] initWithString:@"苍穹仙迹" attributes:@{NSFontAttributeName: [UIFont fontWithName:@"PingFang SC" size: 14],NSForegroundColorAttributeName: [UIColor colorWithRed:102/255.0 green:102/255.0 blue:102/255.0 alpha:1.0]}];
    self.nameLabel.attributedText = string;
    [self.gameIsIntroducedView addSubview:self.nameLabel];
    
    self.miashulabel = [[UILabel alloc]initWithFrame:CGRectMake(imageView.right+8,  self.nameLabel.bottom+7, 100, 14)];
    self.miashulabel.text = @"网络 仙侠";
    NSMutableAttributedString *string1 = [[NSMutableAttributedString alloc] initWithString:@"网络 仙侠" attributes:@{NSFontAttributeName: [UIFont fontWithName:@"PingFang SC" size: 12],NSForegroundColorAttributeName: [UIColor colorWithRed:51/255.0 green:51/255.0 blue:51/255.0 alpha:1.0]}];
    self.miashulabel.attributedText = string1;
    [self.gameIsIntroducedView addSubview:self.miashulabel];
    
    
    
    UIButton *youxibutton = [UIButton buttonWithType:UIButtonTypeCustom];
    youxibutton.backgroundColor = RGB(38, 154, 255);
    youxibutton.frame = CGRectMake(kScreenW - 13-65, 22, 65, 25);
    youxibutton.titleLabel.font = [UIFont systemFontOfSize:12];
    youxibutton.layer.cornerRadius = 25/2;
    youxibutton.layer.masksToBounds = YES;
    [youxibutton setTitle:@"游戏详情" forState:UIControlStateNormal];
    [youxibutton addTarget:self action:@selector(youxibuttontap) forControlEvents:UIControlEventTouchUpInside];
    [self.gameIsIntroducedView addSubview:youxibutton];
    
    youxibutton.backgroundColor = [UIColor bm_colorGradientChangeWithSizeView:youxibutton];
    
    
    
    UIView *fengexianView = [[UIView alloc]initWithFrame:CGRectMake(0, 70, kScreenW, 1)];
    fengexianView.backgroundColor  = RGB(232, 232, 242);
    [self.gameIsIntroducedView  addSubview:fengexianView];
    // 添加基础信息View
    [self addbasisViewChildView];
    // 添加黄色View
    [self addhuanseView];
    // 添加卖家View
    [self addmaijiaViewChildeView];
    
    
    
}


//  添加基础信息View
- (void)addbasisViewChildView {
    
    self.basisView = [[UIView alloc]initWithFrame:CGRectMake(0, self.gameIsIntroducedView .bottom, kScreenW, 120)];
    self.basisView.backgroundColor = [UIColor whiteColor];
    [self.hederView addSubview:self.basisView];
    
    UILabel *namelabel = [[UILabel alloc]initWithFrame:CGRectMake(13, 12, 80, 14)];
    namelabel.text = @"基础信息";
    namelabel.font = [UIFont systemFontOfSize:12];
    [self.basisView addSubview:namelabel];
    
   
    NSArray *arr = @[@"上架时间：2019-07-30",@"操作系统：IOS",@"账号名称：九天白浅珆",@"账号区服：上古258服"];
    self.basisMuArr = [[NSMutableArray alloc]init];
    for (int i = 0; i < arr.count; i++) {
        
        UILabel *namelabel = [[UILabel alloc]initWithFrame:CGRectMake(13, 12+10+14+i*12+i*8, 210, 14)];
        namelabel.text = arr[i];
        namelabel.font = [UIFont systemFontOfSize:12];
        namelabel.textColor = RGB(102, 102, 102);
        [self.basisView addSubview:namelabel];
        [self.basisMuArr addObject:namelabel];
    
    }
    
    UIView *shoujianView = [[UIView alloc]initWithFrame:CGRectMake( kScreenW-180-14, 14+12+10+20, 180, 31)];
    //shoujianView.backgroundColor = [UIColor redColor];
    [self.basisView addSubview:shoujianView];
    
    UILabel *jiagelabel = [[UILabel alloc]initWithFrame:CGRectMake(0,0, 180, 14)];
    jiagelabel.text = @"售价";
    jiagelabel.font = [UIFont systemFontOfSize:12];
    jiagelabel.textColor = RGB(51, 51, 51);
    jiagelabel.textAlignment =  NSTextAlignmentRight;
    [shoujianView addSubview:jiagelabel];
    
    UILabel *pricelabel = [[UILabel alloc]initWithFrame:CGRectMake(0,20, 180, 11)];
    pricelabel.text = @"￥2000.00";
    pricelabel.font = [UIFont systemFontOfSize:11];
    pricelabel.textColor = RGB(253, 178, 50);
    pricelabel.textAlignment =  NSTextAlignmentRight;
    self.priceLabel  = pricelabel;
    [shoujianView addSubview:pricelabel];
    
    
    
    


}


// 添加黄色View
- (void)addhuanseView {
    
    self.huanbeijiView = [[UIView alloc]initWithFrame:CGRectMake(0, self.basisView.bottom,kScreenW , 30)];
    self.huanbeijiView.backgroundColor = RGB(253, 230, 211);
    [self.hederView addSubview:self.huanbeijiView];
    
    
    UILabel *jiagelabel = [[UILabel alloc]initWithFrame:CGRectMake(12,0, kScreenW-70-12, 30)];
    jiagelabel.text = @"此账号已创建61天累计充值5260元。";
    jiagelabel.font = [UIFont systemFontOfSize:11];
    jiagelabel.textColor = RGB(102, 102,102);
    jiagelabel.textAlignment =  NSTextAlignmentLeft;
    self.jieshoulabel = jiagelabel;
    
    [self.huanbeijiView addSubview:jiagelabel];
    
 
    self.chushoulabel =  [[UILabel alloc]initWithFrame:CGRectMake(kScreenW-40-16,0, 60, 30)];
    self.chushoulabel.text = @"已出售";
    self.chushoulabel.font = [UIFont systemFontOfSize:13];
    self.chushoulabel.textColor = RGB(117, 117,117);
    self.chushoulabel.textAlignment =  NSTextAlignmentLeft;
 //   self.chushoulabel.backgroundColor = [UIColor redColor];
    [self.huanbeijiView addSubview:self.chushoulabel];
    
    
    
}

// 添加卖家信息
- (void)addmaijiaViewChildeView {
    
    
//    self.shenheImageView = [[UIImageView alloc]initWithFrame:CGRectMake(kScreenW-50-12, -60, 50, 50)];
//    self.shenheImageView.image = [UIImage imageNamed:@"deal_pass"];
//    [self.huanbeijiView addSubview: self.shenheImageView];
    
    self.maijiaView = [[UIView alloc]initWithFrame:CGRectMake(0, self.huanbeijiView.bottom,kScreenW  , 86)];
    self.maijiaView.backgroundColor = [UIColor whiteColor];
    [self.hederView addSubview:self.maijiaView];
    
    
    self.shenheImageView = [[UIImageView alloc]initWithFrame:CGRectMake(kScreenW-50-12, -40, 50, 50)];
    self.shenheImageView.image = [UIImage imageNamed:@"deal_pass"];
    [self.maijiaView addSubview: self.shenheImageView];
    
    UILabel *maijiaLabel = [[UILabel alloc]initWithFrame:CGRectMake(14, 12, 55, 13)];
    maijiaLabel.text = @"卖家信息";
    maijiaLabel.font = [UIFont systemFontOfSize:13];
    [self.maijiaView addSubview:maijiaLabel];
    
    self.shimingLabel = [[UILabel alloc]initWithFrame:CGRectMake(7+maijiaLabel.right, 13, 45, 12)];
    self.shimingLabel.text = @"已实名";
    self.shimingLabel.textColor = RGB(253, 178, 50);
    self.shimingLabel.font = [UIFont systemFontOfSize:12];
    [self.maijiaView addSubview:self.shimingLabel];
    
    self.phonelabel = [[UILabel alloc]initWithFrame:CGRectMake(14, maijiaLabel.bottom+12, 180, 12)];
    self.phonelabel.text = @"133****0552";
    self.phonelabel.textColor = RGB(51, 51, 51);
     self.phonelabel.font = [UIFont systemFontOfSize:12];
    [self.maijiaView addSubview: self.phonelabel];
    
    
    self.zhucelabel = [[UILabel alloc]initWithFrame:CGRectMake(14, self.phonelabel.bottom+12, 180, 12)];
    self.zhucelabel.text = @"已注册40天";
    self.zhucelabel.textColor = RGB(102, 102, 102);
    self.zhucelabel.font = [UIFont systemFontOfSize:12];
    [self.maijiaView addSubview:self.zhucelabel];
    
    UIView *maicheview1 = [[UIView alloc]initWithFrame:CGRectMake(kScreenW-58-13, 86-50, 58, 34)];
  //  maicheview1.backgroundColor = [UIColor redColor];
    [self.maijiaView addSubview:maicheview1];
    
    
    UILabel *maichulabel = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, 58, 10)];
    maichulabel.text = @"5";
    maichulabel.textColor = RGB(51, 51, 51);
    maichulabel.font = [UIFont systemFontOfSize:10];
    maichulabel.textAlignment =  NSTextAlignmentCenter;
    self.shulian1 = maichulabel;
    [maicheview1 addSubview:maichulabel];
    
    UILabel *yimaichulabel = [[UILabel alloc]initWithFrame:CGRectMake(0, 10+12, 58, 10)];
    yimaichulabel.text = @"已卖出";
    yimaichulabel.textColor = RGB(51, 51, 51);
    yimaichulabel.font = [UIFont systemFontOfSize:10];
    
    yimaichulabel.textAlignment =  NSTextAlignmentCenter;
    [maicheview1 addSubview:yimaichulabel];
    
    
    
    UIView *maichevie2 = [[UIView alloc]initWithFrame:CGRectMake(kScreenW-58-13-58-1, 86-50, 58, 34)];
   // maichevie2.backgroundColor = [UIColor redColor];
    [self.maijiaView addSubview:maichevie2];
    
    
    UILabel *maichulabel2 = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, 58, 10)];
    maichulabel2.text = @"5";
    maichulabel2.textColor = RGB(51, 51, 51);
    maichulabel2.font = [UIFont systemFontOfSize:10];
    maichulabel2.textAlignment =  NSTextAlignmentCenter;
    self.shulian2 = maichulabel2;
    
    [maichevie2 addSubview:maichulabel2];
    
    UILabel *yimaichulabel2 = [[UILabel alloc]initWithFrame:CGRectMake(0, 10+12, 58, 10)];
    yimaichulabel2.text = @"出售中";
    yimaichulabel2.textColor = RGB(51, 51, 51);
    yimaichulabel2.font = [UIFont systemFontOfSize:10];
    yimaichulabel2.textAlignment =  NSTextAlignmentCenter;
    [maichevie2 addSubview:yimaichulabel2];
    
    UIView *shuxianview = [[UIView alloc]initWithFrame:CGRectMake(kScreenW-58-13-1, 86-48, 1, 39)];
    shuxianview.backgroundColor = RGB(232, 232, 242);
    
    [ self.maijiaView  addSubview:shuxianview];
    
    
    UIView *henxiangview = [[UIView alloc]initWithFrame:CGRectMake(0, 85, kScreenW, 1)];
    henxiangview.backgroundColor = RGB(232, 232, 242);
    [self.maijiaView  addSubview:henxiangview];
    
    
    
}




#pragma mark  ------------------- tabviewdatasours

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    
    
    return  2;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    if (section == 0) {
       return   self.icoimageArr.count;
    }
    
    
    return     self.otherArray.count;
    
}



- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    
    
    
    
    if (indexPath.section == 0) {
          static NSString *cellID = @"cellID1";
         HWZhanghaoCellCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID];
        if (!cell) {
            cell =  [[HWZhanghaoCellCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID];
        }
        cell.selectionStyle =  UITableViewCellSelectionStyleNone;
        cell.backgroundColor = [UIColor whiteColor];
        [cell.icoimageView sd_setImageWithURL:[NSURL URLWithString:self.icoimageArr[indexPath.row]] placeholderImage:nil];
        
        return  cell;

    } else  if(indexPath.section == 1){
        
        
            static NSString *cellID = @"cellID";
            HWClinchDealCell *cell =  [tableView dequeueReusableCellWithIdentifier:cellID];
            if (!cell) {
                cell =  [[NSBundle mainBundle]loadNibNamed:@"HWClinchDealCell" owner:nil options:nil].lastObject;
            }
        
        
            cell.selectionStyle = UITableViewCellSelectionStyleNone;
            cell.backgroundColor = [UIColor whiteColor];
        
             cell.zhanghaoModel =  self.otherArray[indexPath.row];
            return  cell;
        

      
    } else {
        
        static NSString *cellID = @"cellID";
        UITableViewCell *cell =  [tableView dequeueReusableCellWithIdentifier:cellID];
        if (!cell) {
            cell =  [[UITableViewCell alloc]init];
            
            
        }
        cell.textLabel.text = @"hudiugiug";
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        cell.backgroundColor = [UIColor whiteColor];
        return  cell;
        
        
    }
    
    
    
//    static NSString *cellID = @"cellID";
//    HWClinchDealCell *cell =  [tableView dequeueReusableCellWithIdentifier:cellID];
//    if (!cell) {
//        cell =  [[NSBundle mainBundle]loadNibNamed:@"HWClinchDealCell" owner:nil options:nil].lastObject;
//    }
//    cell.selectionStyle = UITableViewCellSelectionStyleNone;
//
//    return  cell;
//

    
}


#pragma  mark -------------- UITableViewDelegate


- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    if (indexPath.section == 0) {
        return  120+12;
    }else {
       return  86;
        
    }
    return  44;
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
    
    if (section == 0) {
          return  12+14+14+12+15;
    } else {
        
        return  36;
        
        
    }
    
   
    
}
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
    
    
    return  1;
    
}


- (nullable UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section {
    
    UIView *view = [[UIView alloc]initWithFrame:CGRectMake(0, 0, kScreenW,1)];
    view.backgroundColor = [UIColor whiteColor];
    return  view;
    
}


- (nullable UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
    
    
    if (section == 0) {
        
        UIView *view = [[UIView alloc]initWithFrame:CGRectMake(0, 0, kScreenW, 12+14+14+12+15)];
       // view.backgroundColor = [UIColor orangeColor];
        view.backgroundColor = [UIColor whiteColor];
        UILabel *maichulabel = [[UILabel alloc]initWithFrame:CGRectMake(14, 12, 300, 14)];
        maichulabel.textColor = RGB(51, 51, 51);
        maichulabel.font = [UIFont systemFontOfSize:14];
        
        NSMutableAttributedString *atr = [WMUtil attributedStringWithText:@"账号信息（描述仅供参考，请以图片为准）" withRangText:@"账号信息" withColor:RGB(51, 51, 51) withFont:[UIFont systemFontOfSize:14]];
        maichulabel.attributedText = atr;
        //   maichulabel2.textAlignment =  NSTextAlignmentCenter;
        [view addSubview:maichulabel];
        
        
        UILabel *miaoshuLbale = [[UILabel alloc]initWithFrame:CGRectMake(14, maichulabel.bottom+14, 300, 12)];
        miaoshuLbale.font = [UIFont systemFontOfSize:12];
        miaoshuLbale.textColor = RGB(102, 102, 102);
        miaoshuLbale.text = @"该卖家很懒，未留下任何信息，具体以截图参考为准。";
        [view addSubview:miaoshuLbale];
        
        return  view;
        
    } else {
        
        
        UIView *view = [[UIView alloc]initWithFrame:CGRectMake(0, 0, kScreenW, 36)];
        view.backgroundColor = [UIColor whiteColor];
      
        
        UILabel *miaoshuLbale = [[UILabel alloc]initWithFrame:CGRectMake(14, 0, 300, 36)];
        miaoshuLbale.font = [UIFont systemFontOfSize:12];
        miaoshuLbale.textColor = RGB(51, 51, 51);
        miaoshuLbale.text = @"相关商品";
        [view addSubview:miaoshuLbale];
        
        UIButton *butt  = [UIButton setButtonWithFrame:CGRectMake(kScreenW-60-10, 0, 60, 36) Title:@"更多" Image:@"deal_back" Font:12 Color:RGB(153, 153, 153) Target:self Selector:@selector(gnduo:)];
      
        [butt layoutButtonWithEdgeInsetsStyle:MKButtonEdgeInsetsStyleRight imageTitleSpace:5];
        // butt.backgroundColor = [UIColor redColor];
        [view addSubview:butt];
    
        UIView *xiahunview = [[UIView alloc]initWithFrame:CGRectMake(0, 35, kScreenW, 1)];
        xiahunview.backgroundColor  = RGB(232, 232, 242);
        [view addSubview:xiahunview];
        return  view;
        
    }
 
    
    
    
    
}


- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    
    
    if (indexPath.section == 1) {
        
        HWTradingModel *model =   self.otherArray[indexPath.row];
         
         HWAccountDetailsViewController *AccountDetails = [[HWAccountDetailsViewController  alloc]init];
         AccountDetails.idStr = model.id;
         [self.navigationController pushViewController:AccountDetails animated:YES];
        
    } else if(indexPath.section == 0 ) {
        
          UIScrollView *bgView = [[UIScrollView alloc] init];
            bgView.frame = [UIScreen mainScreen].bounds;
            bgView.backgroundColor = [UIColor blackColor];
            UITapGestureRecognizer *tapBg = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapBgView:)];
            [bgView addGestureRecognizer:tapBg];
            bgView.pagingEnabled = YES;
            self.scrollView = bgView;
            [[[UIApplication sharedApplication] keyWindow] addSubview:bgView];
            
            self.scrollView.delegate = self;
            NSArray *imagesarr =   self.icoimageArr;
            [self.scrollView setContentSize:CGSizeMake( imagesarr.count*SCREEN_WIDTH, SCREEN_HEIGHT)];
            
            
            
              self.scrollView.contentOffset = CGPointMake(indexPath.row * SCREEN_WIDTH, 0);
            
            
               for (int i = 0 ; i <  imagesarr.count; i ++) {
                   
        //           NSLog(@"youzhima%lu", (unsigned long)self.entity.imgs.count);
                  


                   UIImageView *imageView = [[UIImageView alloc] init];
                   // imageView.image =  [UIImage imageNamed:self.entity.imgs[i]];
                   
                   // [imageView sd_setImageWithURL:[NSURL URLWithString:self.entity.imgs[i]] placeholderImage:[UIImage imageNamed:@""]];
                   // imageView.image = [UIImage imageNamed:@"1"];
                   
                   imageView.tag = i+100;
                   
                   // imageView.frame = [bgView convertRect:picView.frame fromView:self.view];
                   [bgView addSubview:imageView];
                   
                   //        CGRect frame = imageView.frame;
                   //        frame.size.width = bgView.frame.size.width;
                   //        frame.size.height = frame.size.width * (imageView.image.size.height / imageView.image.size.width);
                   //        frame.origin.x = i *  bgView.frame.size.width;
                   //        frame.origin.y = (bgView.frame.size.height - frame.size.height) * 0.5;
                   //        imageView.frame = frame;
                   
                   
                   if (i == indexPath.row) {
                  
                       if (imagesarr.count > 0) {
                           [imageView  sd_setImageWithURL:[NSURL URLWithString:imagesarr[i]] completed:^(UIImage * _Nullable image, NSError * _Nullable error, SDImageCacheType cacheType, NSURL * _Nullable imageURL) {

                                  CGRect frame = imageView.frame;
                                  frame.size.width = self.scrollView.frame.size.width;
                                  frame.size.height = frame.size.width * (imageView.image.size.height / imageView.image.size.width);
                                  frame.origin.x = i *  self.scrollView.frame.size.width;
                                  frame.origin.y = (self.scrollView.frame.size.height - frame.size.height) * 0.5;
                                  imageView.frame = frame;
                                  imageView.image = image;

                          //        self.lastImageView =  imagView;
                          //
                          //        self.originalFrame = imagView.frame;


                              }];
                       }
                        


                       continue;
                   }
                   
                   
                   
               }
        
        
        
        
        
        
    }
    
//    HWTradingModel *model =   self.otherArray[indexPath.row];
//
//    HWAccountDetailsViewController *AccountDetails = [[HWAccountDetailsViewController  alloc]init];
//    AccountDetails.idStr = model.id;
//    [self.navigationController pushViewController:AccountDetails animated:YES];

    
}





- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView {
    
    NSInteger leftI = scrollView.contentOffset.x / SCREEN_WIDTH;
    UIImageView *imagView = [self.scrollView viewWithTag:leftI+100];
    //  [imagView sd_setImageWithURL:[NSURL URLWithString:self.entity.imgs[i]] placeholderImage:[UIImage imageNamed:@""]];
    
      NSArray *imagesarr =   self.icoimageArr;
    if (imagesarr.count > 0) {
        [imagView  sd_setImageWithURL:[NSURL URLWithString:imagesarr[leftI]] completed:^(UIImage * _Nullable image, NSError * _Nullable error, SDImageCacheType cacheType, NSURL * _Nullable imageURL) {
            
            CGRect frame = imagView.frame;
            frame.size.width = self.scrollView.frame.size.width;
            frame.size.height = frame.size.width * (imagView.image.size.height / imagView.image.size.width);
            frame.origin.x = leftI *  self.scrollView.frame.size.width;
            frame.origin.y = (self.scrollView.frame.size.height - frame.size.height) * 0.5;
            imagView.frame = frame;
            imagView.image = image;
            
    //        self.lastImageView =  imagView;
    //
    //        self.originalFrame = imagView.frame;
            
            
        }];
    }
    
    
    
    
    
    
    
    
    
    
    
    
    
}










-(void)tapBgView:(UITapGestureRecognizer *)tapBgRecognizer
{
    //    self.scrollView.contentOffset = CGPointZero;
    //    [UIView animateWithDuration:0.5 animations:^{
    //        self.lastImageView.frame = self.originalFrame;
    //        tapBgRecognizer.view.backgroundColor = [UIColor clearColor];
    //    } completion:^(BOOL finished) {
    //        [tapBgRecognizer.view removeFromSuperview];
    //        self.scrollView = nil;
    //        self.lastImageView = nil;
    //    }];
    
    
  
    self.scrollView.contentOffset = CGPointZero;
    
    
    [self.scrollView removeFromSuperview];
    
    
    
    
    
    
    
}








#pragma mark -----------  点击更多

- (void)gnduo:(UIButton *)sender {
    
    DLog(@"bhjuuh;bgui;");
    
    

}




//  点击收藏按钮
- (void)shoucanganniucaozuo {
    
        
        NSString *userID = [HWLocallyStoredData getLoginUserID];
        int t =   [WMUtil  getRandomNumber:101 to:998];
    
    
        NSString *tStr = [NSString stringWithFormat:@"%ld%d",[WMUtil getTimeSp],t];
    
        NSString *sign = [NSString stringWithFormat:@"%@%@%@",userID,tStr,@"fsd213ewdsadqwe2121213edsad"];
        NSString *signMD5 = [WMUtil md5HexDigest:sign];
        NSString *typeStr = [NSString stringWithFormat:@"%@",@"2"];
        
        
        
        
        NSDictionary *parametes = @{
                                    @"ct" :  @"app",
                                    @"ac" : @"shoucang_add",
                                    @"ios" : @"1",
                                    @"uid" :userID,
                                    @"t" :tStr,
                                    @"sign": signMD5,
                                    @"type":typeStr,
                                    @"id" : self.idStr
                                    };
        
        

        
        [HWWebUtils doGetWithParameters:parametes progress:nil success:^(id response) {
            
          
            NSString *codeStr =  [NSString stringWithFormat:@"%@",response[@"code"]];
         //   [MBProgressHUD hideHUD];
            
            
            if ([codeStr intValue] == 1) {
             
              //  self.fenleiMuArr = [response[@"data"] mutableCopy];
     
                self.shoucangBut.selected = YES;
                

            } else {
                
//                if ([@"已被收藏" isEqualToString:response[@"message"]]) {
//                      self.shoucangBut.selected = YES;
//
//                }
//
                 [MBProgressHUD  showError:response[@"message"]];
                
            }
            NSLog(@"%@",response);
            
            
        } failure:^(NSString *error) {
          
            [MBProgressHUD  showError:@"收藏失败"];
            
        }];
    
    
}

// 取消收藏
- (void)quxiaoshoucang {
    
    
    NSString *userID = [HWLocallyStoredData getLoginUserID];
        int t =   [WMUtil  getRandomNumber:101 to:998];
    
    
        NSString *tStr = [NSString stringWithFormat:@"%ld%d",[WMUtil getTimeSp],t];
    
        NSString *sign = [NSString stringWithFormat:@"%@%@%@",userID,tStr,@"fsd213ewdsadqwe2121213edsad"];
        NSString *signMD5 = [WMUtil md5HexDigest:sign];
        NSString *typeStr = [NSString stringWithFormat:@"%@",@"2"];
        
        
        
        
        NSDictionary *parametes = @{
                                    @"ct" :  @"app",
                                    @"ac" : @"shoucang_del",
                                    @"ios" : @"1",
                                    @"uid" :userID,
                                    @"t" :tStr,
                                    @"sign": signMD5,
                                    @"type":typeStr,
                                    @"id" : self.dataDic[@"shoucang_id"]
                                    };
        
        

        
        [HWWebUtils doGetWithParameters:parametes progress:nil success:^(id response) {
            
          
            NSString *codeStr =  [NSString stringWithFormat:@"%@",response[@"code"]];
         //   [MBProgressHUD hideHUD];
            
            
            if ([codeStr intValue] == 1) {
             
              //  self.fenleiMuArr = [response[@"data"] mutableCopy];
     
                self.shoucangBut.selected = NO;
                

            } else {
                
                 [MBProgressHUD  showError:response[@"message"]];
                
            }
            NSLog(@"%@",response);
            
            
        } failure:^(NSString *error) {
          
            [MBProgressHUD  showError:@"收藏失败"];
            
        }];
    
    
    
    
    
}



- (void)youxibuttontap {
    
    
    
    NSString *gid =  self.dataDic[@"gid"];
    
    
    
    
      HWGameDetailController *gameDetails = [[HWGameDetailController alloc]init];
       gameDetails.gameId = gid;
       [self.navigationController pushViewController:gameDetails animated:YES];
    
    
    
    

    NSLog(@"1233 nishi");
    
    
    
    
}








@end
